using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;
namespace FilmekAdatbazis
{
    class taroltak:DAL
    {
        private System.Data.DataSet dsfilm;
        private System.Data.SqlClient.SqlDataAdapter dafilm;
        private System.Data.SqlClient.SqlDataAdapter daAruk;
        private System.Data.DataSet dsArukGrid;
        public bool Err;
        private string sQuery;
        public taroltak()
        {
            //if (!base.IsConnectCreated())
            //{
              //  Err = !base.MakeConnection();
            //}
            daAruk = new SqlDataAdapter();
            daAruk.TableMappings.Add("Table", "Szereplok");
            //daEgyAruSor = new SqlDataAdapter();
           // daEgyAruSor.TableMappings.Add("Table", "EgyAru");
            //			dsArukGrid = new DataSet("ArukGrid");
           // daGrid = new SqlDataAdapter();
           // daGrid.TableMappings.Add("Table", "ArukGrid");
        }

        public System.Data.SqlClient.SqlDataReader Tolt(ref string ErrM)
        {
            myDataReader = base.myExecuteReader("SELECT * FROM Szereplok", ref ErrM);
            return myDataReader;
        }
        public System.Data.DataSet GridTolt(int id1,int id2,int id3, string tablaNev, ref string ErrM)
        {
            string sSQL = "declare @maxkod int,@kod1 int,@kod2 int,@kod3 int,@filmid int,@filmcim varchar(50),@id int " +
            " set @maxkod=0 set @id=0 set @kod1=" + Convert.ToString(id1) + " set @kod2=" + Convert.ToString(id2) + " set @kod3=" + Convert.ToString(id3) + " " +
            " set @filmcim='' set @filmid=0 " +

            " CREATE TABLE #Eredm1(FilmID int,Cim varchar(50)) " +

            " select @maxkod=MAX(FilmID) from Filmek " +
            " while @id<@maxkod " +
            " BEGIN " +
            " set @id=@id+1 " +
            " EXEC szinesz @kod1,@kod2,@kod3,@filmid OUTPUT,@filmcim OUTPUT, @id " +
            " if @filmcim<>'' " +
            "  BEGIN"+
            " insert into #Eredm1 values(@filmid,@filmcim) " +
            " set @filmcim='' "+
            " END " +
            " END " +
            " select * from #Eredm1";
            return base.FillDataSetFromSqlQuery(sSQL, tablaNev, ref ErrM);
        }
        public System.Data.DataSet filmGridTolt(string sBetuk, ref string ErrM)
        {
            string sSQL = "SELECT SzereploNev FROM Szereplok ";
           
            dsfilm = base.myFillDataSetFromString(sSQL, "felhaszn", ref dafilm, ref ErrM);
            return dsfilm;
        }
        public System.Data.DataSet FelhasznalokGridTolt(string tablaNev, ref string ErrM)
        {
            string sSQL = "SELECT SzereploNev FROM Szereplok ";
            return base.FillDataSetFromSqlQuery(sSQL, tablaNev, ref ErrM);
        }

        public System.Data.SqlClient.SqlDataReader FelhasznaloLbTolt(ref string ErrM)
        {
            String query = "SELECT SzereploID,SzereploNev FROM Szereplok";
            return base.myExecuteReader(query, ref ErrM);
        }
        public static void ListBoxEpito(System.Windows.Forms.ListBox lb, System.Data.SqlClient.SqlDataReader DtReadcombo, ref ArrayList aKOD)
        {
            //lb.Items.Clear();
            //while (DtReadcombo.Read())
            //{
            //    lb.Items.Add(DtReadcombo[1].ToString());
            //    aKOD.Add(DtReadcombo[0].ToString());
            //}
            //DtReadcombo.Close();

        }
        public taroltak(ref bool Err)
		{
			if (!base.IsConnectCreated())
			{
				Err = !base.MakeConnection();
			}
			dafilm = new SqlDataAdapter();
			dafilm.TableMappings.Add("Table", "Szereplok");
		}

    }
}
